﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace prime_factor
{
    class Program
    {
        static void Main(string[] args)
        {
            int num;

            Console.WriteLine("Please input an integer: ");
            try
            {
                num = Convert.ToInt32(Console.ReadLine());
                int num1 = num;
                if (num == 0 || num == 1)
                {
                    Console.WriteLine("This number don't have prime factor!");
                }
                else
                {
                    Console.WriteLine("The integer's prime factors are all here: ");
                    for (int i = 2; i <= num1/2+1; i++)          //不能仅仅循环到根号num，就连num/2也不行，因为每次循环i会增加1，比如10
                    {
                        if (num % i == 0)
                        {
                            Console.Write($"{i}  ");
                            while (num % i == 0)        
                            {
                                num /= i;
                            }
                        }
                        if (num == 1) break;
                    }
                    Console.WriteLine(".");
                }
            }
            catch
            {
                Console.WriteLine("Input Error!!!");
            }          
            Console.ReadKey();
        }
    }
}
